#include <Windows.h>
#include <conio.h>
#include <ctime>
#include <fstream>
#include <iostream>
#include <mmsystem.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>
#include <vector>
#include <windows.h>
// #include "roles.cpp"
#include "Simulated_universe.h"
#include "information1.h"
#include "main.h"
#include <conio.h>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iostream>
using namespace std;

// struct character{
//     string name;
//     int available=-1;
//     int HP;//血量
//     int ATK;//攻击
//     int DEF;//防御
//     int SPD;//速度
//     int CRIT_rate;//暴击
//     int CRIT_DMG;//爆伤
//     int Break_Effect;//击破特工
//     int Outgoing_Healing_Boost;//治疗加成
//     int Max_Energy;//最大能量
//     int Energy_Regeneration_rate;//能量回复效率
//     int Effect_Hit_Rate;//效果命中
//     int Effect_Res;//效果抵抗
// };

extern int role_available[100], achievement1[100], easter_egg[100], opt[100],
    si_baodi, wu_baodi, arms_[100];
void COLOR_PRINT2(const char *s, int front_color, int back_color);
void five_star_(int sel);
void options(int opt[]) {
    system("cls");
    if (opt[1] == 1) {
        printf("选择语言：\n 1)中文 2)英文\n :[");
        cin >> opt[1];
        return;
    } else if (opt[1] == 2) {
        printf("Select Language:\n 1)Chinese 2)English\n :[");
        cin >> opt[1];
        return;
    } else {
        printf("暂时不支持其他语言");
        return;
    }
}
string tmp1[100];
void yue_qian() {
    int select;
    printf("------------------跃迁-----------------\n");
    printf("|   1)开拓者球棒 ※※※※※             |\n");
    printf("|   2)黄泉-40米大刀 ※※※※※         |\n");
    printf("|   3)流萤 ※※※※※                  |\n");
    printf("|   4)黄泉 ※※※※※                   |\n");
    printf("|   5)50抽 混池                        |\n");
    printf("|                                     |\n");
    printf("|                                     |\n");
    printf("|                                     |\n");
    printf("|    0)退出                             |\n");
    printf("|  当前通票:无限    5※概率 1%           |\n");
    printf("--------------测试版随便抽---------------\n");
    printf("选择卡池(10抽):[");
    you.role_status[3].available = 1;
    cin >> select;
    system("cls");
    srand((unsigned)time(NULL));
    tmp1[1] = "开拓者球棒", tmp1[2] = "黄泉-40米大刀", tmp1[3] = "流萤",
    tmp1[99] = "我也不知道是啥", tmp1[4] = "黄泉", tmp1[50] = "Chesten",
    tmp1[60] = "wxhz", tmp1[70] = "四星，待添加";
    if (select == 0)
        return;
    if (select == 5) {
        for (int i = 0; i <= 50; i++) {
            int a = rand();
            cout << a;
            for (int j = 0; j <= i; j++)
                printf("-");
            if (13 == a % 100 || wu_baodi >= 70) {
                int tmp2 = rand() % 5;
                five_star_(tmp2);
                string jin = "------------" + tmp1[tmp2] + "------------";
                COLOR_PRINT2(jin.c_str(), 0, 14);
                printf("\n");
                wu_baodi = 0;
                continue;
            }
            if (i == a % 50 || si_baodi >= 10) {
                COLOR_PRINT2(tmp1[70].c_str(), 7, 13);
                cout << endl;
                si_baodi = 0;
                continue;
            }
            if (4 == a % 1000) {
                cout << "wxhz" << endl;
                cout << "-----获得成就： 抽出作者wxhz(千分之一);-----" << endl;
                achievement1[4] = 1;
                continue;
            }
            if (3 == a % 10000) {
                cout << "Chesten" << endl;
                cout << "-----获得成就： 抽出作者Chesten(万分之一);-----"
                     << endl;
                achievement1[5] = 1;
                continue;
            }
            if (13 != a % 100) {
                cout << tmp1[99] << endl;
                si_baodi++;
                wu_baodi++;
            }
            Sleep(100);
        }
        system("pause");
    } else {
        for (int i = 0; i <= 9; i++) {
            int a = rand();
            cout << a;
            for (int j = 0; j <= i; j++)
                printf("-");
            if (13 == a % 100 || wu_baodi >= 70) {
                five_star_(select);
                string jin = "------------" + tmp1[select] + "------------";
                COLOR_PRINT2(jin.c_str(), 0, 14);
                printf("\n");
                wu_baodi = 0;
                continue;
            }
            if (i == a % 10 || si_baodi >= 10) {
                COLOR_PRINT2(tmp1[70].c_str(), 7, 13);
                cout << endl;
                si_baodi = 0;
                continue;
            }
            if (4 == a % 1000) {
                cout << "wxhz" << endl;
                cout << "-----获得成就： 抽出作者wxhz(千分之一);-----" << endl;
                achievement1[4] = 1;
                continue;
            }
            if (3 == a % 10000) {
                cout << "Chesten" << endl;
                cout << "-----获得成就： 抽出作者Chesten(万分之一);-----"
                     << endl;
                achievement1[5] = 1;
                continue;
            }
            if (5 != a % 100) {
                cout << tmp1[99] << endl;
                si_baodi++;
                wu_baodi++;
            }
            Sleep(500);
        }
        system("pause");
    }
    system("cls");
    return;
}

void show_role_status() {
    for (int ren = 1; ren <= 4; ren++) {
        printf("HP:%05d ", you.role_status[ren].HP);
    }
}

void help() {
    printf("\n帮助HELP:\n");
    printf("如何更改语言 How to change the language: 按\'o\'后输入1/2 "
           "Press\'o\' then input 1/2 \n ");
    printf("j: 普通技能 k:闪现(向前) wasd: 移动 q:大招 h:帮助 o:设置 y:抽卡 "
           "g:成就 =:退出模拟宇宙");
    system("pause");
    system("cls");
}

void _Clearscreen1(bool flag) { // 清空屏幕
    if (flag == 1) {            // 双缓冲
        HANDLE hStdOut;
        CONSOLE_SCREEN_BUFFER_INFO csbi;
        DWORD count;
        DWORD cellCount;
        COORD homeCoords = {0, 0};
        hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
        if (hStdOut == INVALID_HANDLE_VALUE)
            return;
        if (!GetConsoleScreenBufferInfo(hStdOut, &csbi))
            return;
        cellCount = csbi.dwSize.X * csbi.dwSize.Y;
        if (!FillConsoleOutputCharacter(hStdOut, (TCHAR)' ', cellCount,
                                        homeCoords, &count))
            return;
        if (!FillConsoleOutputAttribute(hStdOut, csbi.wAttributes, cellCount,
                                        homeCoords, &count))
            return;
        SetConsoleCursorPosition(hStdOut, homeCoords);
    } else if (flag == 0) { // 单缓冲
        HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
        COORD coordScreen = {0, 0};
        SetConsoleCursorPosition(hConsole, coordScreen);
    }
}

void COLOR_PRINT2(const char *s, int front_color, int back_color) {
    HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | back_color * 16 |
                                        FOREGROUND_INTENSITY | front_color);
    printf(s);
    SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | 7);
}
/*
0 = 黑色 8 = 灰色
1 = 蓝色 9 = 淡蓝色
2 = 绿色 10 = 淡绿色
3 = 浅绿色 11 = 淡浅绿色
4 = 红色 12 = 淡红色
5 = 紫色 13 = 淡紫色
6 = 黄色 14 = 淡黄色
7 = 白色 15 = 亮白色
*/

void five_star_(int sel) {
    system("cls");
    Sleep(1000);
    printf("\n\n\n\n");
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j <= 4; j++) {
            printf("-");
        }
        Sleep(400);
        for (int j = 0; j <= 4; j++) {
            printf("-");
        }
        COLOR_PRINT2("※", 0, 14);
    }
    for (int j = 0; j <= 10; j++) {
        printf("-");
    }
    printf("\n");
    // tmp1[1]="开拓者球棒",tmp1[2]="黄泉-40米大刀",tmp1[3]="流萤",tmp1[4]="我也不知道是啥",tmp1[5]="Chesten",tmp1[6]="wxhz",tmp1[7]="四星，待添加";
    if (sel == 1) {
        COLOR_PRINT2("                    开拓者球棒                  \n", 0,
                     14);
        printf("           _=====_        \n");
        printf("          /     /         \n");
        printf("         /     /          \n");
        printf("        /     /           \n");
        printf("       /     /            \n");
        printf("      /     /             \n");
        printf("     /     /             \n");
        printf("    /_   _/                \n");
        printf("    /  /                   \n");
        printf("   /  /                  \n");
        printf("  /  /     ※※※※※          \n");
        printf(" ----                       \n");
        you.role_status[1].arms_[2] = 1;
    }
    if (sel == 2) {
        COLOR_PRINT2("                 黄泉-40米大刀                  \n", 0,
                     14);
        printf("                                  \n");
        printf("                                  \n");
        printf("                                  \n");
        printf("       \\\\                          \n");
        printf(" |-----|======================================================="
               "==============================================================="
               "============                                 \n");
        printf("       //                           \n");
        printf("            ※※※※※                \n");
        printf("                                  \n");
        you.role_status[2].arms_[2] = 1;
    }
    if (sel == 3) {
        you.role_status[3].available = 1;
        COLOR_PRINT2("                 流萤                  \n", 0, 14);
        printf("                                  \n");
        printf("                            火   萨姆萨姆   \n");
        printf("                          火 萨姆萨姆萨姆萨姆       \n");
        printf("                        火   萨姆萨姆萨姆萨姆      \n");
        printf("                      火    火   萨姆萨姆  \n");
        printf("                      火           流萤\n");
        printf("                           火    流萤流萤\n");
        printf("                        火 火     流萤 \n");
        printf("                                  流萤\n");
        printf("                               流萤     \n");
    }
    if (sel == 4) {
        you.role_status[2].available = 1;
        COLOR_PRINT2("                 黄泉                  \n", 0, 14);
        printf("                      伞虹伞伞伞伞  \n");
        printf("                   伞伞伞伞伞伞伞伞          \n");
        printf("                        伞 黄泉        \n");
        printf("          (黑白)        黄泉黄泉      \n");
        printf("                          黄泉    \n");
        printf("                         黄泉黄泉        \n");
        printf("                          黄泉        \n");
        printf("                          黄泉        \n");
    }
    system("pause");
    return;
}